package com.joca.scheduling.database;

import java.util.LinkedList;
import java.util.List;

import com.joca.scheduling.entities.Role;
import com.joca.scheduling.entities.User;

public class UserData {

	LinkedList<User> listOfUsers;
	private static UserData instance;
	

	private UserData() {		
		listOfUsers = new LinkedList<User>();
		listOfUsers.add(new User(1,"Jovan","Dimitrijevic","joca","1",Role.Professor));
		listOfUsers.add(new User(2,"Pera","Peric","pera","1",Role.Student));
	}
	
	public static UserData getInstance(){
		if(instance==null)instance = new UserData();
		return instance;
	}
	
	public List<User> getAllUsers(){
		return listOfUsers;
	}
	
	public void addUser(User user){
		listOfUsers.add(user);		
	}
	
	public User logIn(User user){
		for(User us:listOfUsers){
			if(user.getUsername().equals(us.getUsername())&&user.getPassword().equals(us.getPassword())){
				return us;
			}
		}
		return null;
	}

	public List<User> getAllUserProfessors() {
		List<User> listOfProfessors = new LinkedList<User>();
		for(User us : listOfUsers){
			if(us.getRole()==Role.Professor)listOfProfessors.add(us);
		}
		return listOfProfessors;
	}

	public User getUserByID(int userID) {
		for(User us:listOfUsers){
			if(us.getUserID()==userID)return us;			
		}
		return null;
	}
	
}
